<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}少儿编程{% endblock %}</title>
    <!-- Bootstrap CSS -->
    <link href="{{ url_for('static', filename='lib/bootstrap/bootstrap.min.css') }}" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="{{ url_for('static', filename='lib/fontawesome/all.min.css') }}" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
    {% block extra_css %}{% endblock %}
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-light bg-primary">
        <div class="container">
            <a class="navbar-brand text-white" href="{{ url_for('home.index') }}">少儿编程</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarContent">
                <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
                    <li class="nav-item">
                        <a class="nav-link text-white {% block nav_home %}{% endblock %}" href="{{ url_for('home.index') }}">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white {% block nav_python %}{% endblock %}" href="#">Python编程</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white {% block nav_scratch %}{% endblock %}" href="#">Scratch编程</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white {% block nav_exercise %}{% endblock %}" href="{{ url_for('exercises.index') }}">在线练习</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white {% block nav_exam %}{% endblock %}" href="#">等级考试</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white" href="{{ url_for('admin.login') }}">管理入口</a>
                    </li>
                    {% if current_user.is_authenticated %}
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle text-white" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                {{ current_user.username }}
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
                                <li><a class="dropdown-item" href="{{ url_for('users.profile') }}">个人中心</a></li>
                                <li><hr class="dropdown-divider"></li>
                                <li><a class="dropdown-item" href="{{ url_for('users.logout') }}">退出登录</a></li>
                            </ul>
                        </li>
                    {% else %}
                        <li class="nav-item">
                            <a class="nav-link text-white" href="{{ url_for('users.login') }}">登录</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-white" href="{{ url_for('users.register') }}">注册</a>
                        </li>
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>

    <main class="container mt-4">
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
                        {{ message }}
                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                    </div>
                {% endfor %}
            {% endif %}
        {% endwith %}
        {% block content %}{% endblock %}
    </main>

    <footer class="container mt-5">
        <p class="text-center">&copy; 2025 少儿编程</p>
    </footer>

    <!-- Bootstrap JS -->
    <script src="{{ url_for('static', filename='lib/bootstrap/bootstrap.bundle.min.js') }}"></script>
    <!-- jQuery -->
    <script src="{{ url_for('static', filename='lib/jquery/jquery.min.js') }}"></script>
    {% block extra_js %}{% endblock %}
</body>
</html>
